package gpinterpreter.stack;

import gpinterpreter.Instruction;
import java.util.Arrays;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;




import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import primitives.cluster.ClusterHead;
import primitives.cluster.ClusterUtils;
import primitives.graph.Graph;
import primitives.graph.Node;

/**
 *
 * @author mat
 */
public class StackInterpreterTest {

	Node a, b;
	Graph g;
	ClusterHead n;

	public StackInterpreterTest() {
	}

	@BeforeClass
	public static void setUpClass() throws Exception {
	}

	@AfterClass
	public static void tearDownClass() throws Exception {
	}

	@Before
	public void setUp() {

		a = new Node();
		b = new Node();

		g = new Graph();

		g.addNode(a);
		g.addNode(b);

		n = new ClusterHead(g);

	}

	@After
	public void tearDown() {
	}

	/**
	 * Test of execute method, of class StackInterpreter.
	 */
	@Test
	public void testExecute() {

		
		StackInstruction[] l = {
			new StackInstruction(StackSymbol.PUSH, 1),
			new StackInstruction(StackSymbol.PUSH, 2),
			new StackInstruction(StackSymbol.CLUSTER,0)
			
		};


		StackInterpreter instance = new StackInterpreter(Arrays.asList(l), n);
		System.out.println("execute");
		ClusterHead r = instance.run();
		// TODO review the generated test code and remove the default call to fail.
		ClusterUtils.prettyPrintTree(r);
		
		assertTrue(r.contains(a));
		assertTrue(r.contains(b));
		
		assertTrue(ClusterUtils.validTree(r, g));
		
		assertEquals(r.getChildren().size(), 1);
		
		
		
	}
	
	//@Test //Incomplete!
	public void testClusterTwo() {

		
		StackInstruction[] l = {
			new StackInstruction(StackSymbol.PUSH, 1),
			new StackInstruction(StackSymbol.PUSH, 2),
			new StackInstruction(StackSymbol.CLUSTER,0),
			new StackInstruction(StackSymbol.PUSH, 3),
			new StackInstruction(StackSymbol.CLUSTER, 0)
			
		};


		StackInterpreter instance = new StackInterpreter(Arrays.asList(l), n);
		System.out.println("execute");
		ClusterHead r = instance.run();
		// TODO review the generated test code and remove the default call to fail.
		ClusterUtils.prettyPrintTree(r);
		
		assertTrue(r.contains(a));
		assertTrue(r.contains(b));
		
		assertTrue(ClusterUtils.validTree(r, g));
		
		assertEquals(r.getChildren().size(), 1);
		
		
		
	}
	
	public static void main(String[] args){
		StackInterpreterTest st = new StackInterpreterTest();
		
		st.setUp();
		st.testExecute();
		st.tearDown();
		
		
	}
}
